
#if !CF && !SILVERLIGHT

using System;
using System.Security.Principal;
using System.Threading;
using Qdb.Monitoring;

namespace Qdb.Tests.CLI1.Monitoring
{
	public class QdbPerformanceCounterInstaller
	{
		private static bool _installed;

		public static void ReInstall()
		{
			if (_installed)
			{
				return;
			}

			if (IsCurrentUserAnAdministrator())
			{
				QdbPerformanceCounters.ReInstall();
				_installed = true;
			}
		}

		private static bool IsCurrentUserAnAdministrator()
		{
			AppDomain.CurrentDomain.SetPrincipalPolicy(PrincipalPolicy.WindowsPrincipal);
			WindowsPrincipal principal = (WindowsPrincipal)Thread.CurrentPrincipal;
			return principal.IsInRole(WindowsBuiltInRole.Administrator);
		}
	}
}

#endif